/**
 * @section LICENSE
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details at
 * http://www.gnu.org/copyleft/gpl.html
 */

#include <FreeBlock.h>

#include <iostream>

namespace BD = BlockDropper;

BD::FreeBlock::FreeBlock()
	: memberPosition(16, 0)
{
	constituentBlocks[0][0] = std::rand() % 2 == 0;
	constituentBlocks[0][1] = std::rand() % 2 == 0;
	constituentBlocks[1][0] = std::rand() % 2 == 0;
	constituentBlocks[1][1] = std::rand() % 2 == 0;
}

void BD::FreeBlock::drop()
{
	++memberPosition.y;
}

bool BD::FreeBlock::getConstituentBlock(const unsigned x, const unsigned y) const
{
	return constituentBlocks[y][x];
}

void BD::FreeBlock::moveLeft()
{
	--memberPosition.x;
}

void BD::FreeBlock::moveRight()
{
	++memberPosition.x;
}

const BD::Point<unsigned short> & BD::FreeBlock::position() const
{
	return memberPosition;
}

void BD::FreeBlock::turnAntiClockwise()
{
	const bool temp(constituentBlocks[0][0]);
	constituentBlocks[0][0] = constituentBlocks[0][1];
	constituentBlocks[0][1] = constituentBlocks[1][1];
	constituentBlocks[1][1] = constituentBlocks[1][0];
	constituentBlocks[1][0] = temp;
}

void BD::FreeBlock::turnClockwise()
{
	const bool temp(constituentBlocks[0][0]);
	constituentBlocks[0][0] = constituentBlocks[1][0];
	constituentBlocks[1][0] = constituentBlocks[1][1];
	constituentBlocks[1][1] = constituentBlocks[0][1];
	constituentBlocks[0][1] = temp;
}

